<%= stylesheet_link_tag "contest" %>
<h1>Editing contest</h1>

<table class="contest">
  <tr>
    <td>
<% form_for(@contest) do |f| %>
  <%= f.error_messages %>

  <p>
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.label :start_time %><br />
    <%= f.datetime_select :start_time %>
  </p>
  <p>
    <%= f.label :end_time %><br />
    <%= f.datetime_select :end_time %>
  </p>
  <p>
    <%= f.submit "Update" %>
  </p>
<% end %>

<%= link_to 'Show', @contest %> |
<%= link_to 'Back', contests_path %>
</td>


<td>

Problems:
<table name="Problems:" id="problems">
  <% @contest.problems.each do |@problem| -%>
    <%= render :partial => "problem", :object => [@contest, @problem] %>
  <% end -%>
</table>

<% form_remote_tag :url => { :controller => "contests",
  :action => "add_problem", :id => @contest.id} do -%>
  <label>Difficulty:</label>
    <select name="difficulty">
      <option value="1" >1</option>
      <option value="2" >2</option>
      <option value="3" >3</option>
      <option value="4" >4</option>
      <option value="5" >5</option>
    </select>
<%= submit_tag 'Random' %>
<% end -%>

<div>
    <%= text_field_tag 'search' %>
    <%= button_to_remote "Add Problem",
      {:url => {:action => "add_problem", :id => @contest.id},
        :with => "'problem_id='+new_problem_id"},
      {:id => "new_problem"}%>
    <br />
    <ul id="results">
      <%= render :partial => "results", :object => @results %>
    </ul>
</div>

<script type="text/javascript">
<%= render :update do |page|
page[:new_problem].hide
page.event.observe('search', 'focus') do |p|
p[:results].show
  end
  page.event.observe('search', 'blur') do |p|
    p[:results].hide
  end
end %>
</script>

<%= observe_field :search,
  :url => { :action => :query },
  :frequency => 0.25,
  :with => :query
%>
</td>
</tr>
</table>